package com.network.retrofit_rx.Api;

import java.util.HashMap;
import java.util.Map;

import okhttp3.RequestBody;

/**
 * @author QiQi
 * @date 2017/7/15
 */

public class CommandImpl {

    /**
     * 请求地址
     */
    private String url;
    /**
     * 请求参数
     */
    private HashMap<String, Object> params;
    private HashMap<String, Object> fieldMap;
    private HashMap<String, RequestBody> bodys;
    private Boolean isObject = false;
    private Class<?> cls;


    private CommandImpl(String url, HashMap<String, Object> params, HashMap<String, Object> fieldMap, HashMap<String, RequestBody> bodys, Boolean isObject, Class<?> cls) {
        this.url = url;
        this.params = params;
        this.fieldMap = fieldMap;
        this.bodys = bodys;
        this.isObject = isObject;
        this.cls = cls;
    }

    public String getUrl() {
        return url;
    }

    public Map<String, Object> getParams() {
        return params;
    }

    public Map<String, RequestBody> getBodys() {
        return bodys;
    }

    public Map<String, Object> getFieldMap() {
        return fieldMap;
    }

    public Boolean getObject() {
        return isObject;
    }

    public Class<?> getCls() {
        return cls;
    }

    public static final class Builder {

        /**
         * 请求地址
         */
        private String url;
        /**
         * 请求参数
         */
        private HashMap<String, Object> params;
        private HashMap<String, Object> fieldMap;
        private HashMap<String, RequestBody> bodys;
        private Boolean isObject = false;
        private Class<?> cls;

        public Builder() {
            params = new HashMap<>();
            bodys = new HashMap<>();
            fieldMap = new HashMap<>();
        }

        public Builder setUrl(String url) {
            this.url = url;
            return this;
        }

        public Builder addField(String key, Object value) {
            fieldMap.put(key, value);
            return this;
        }

        public Builder putField(Map<String, Object> map) {
            fieldMap.putAll(map);
            return this;
        }

        public Builder addBodys(String key, RequestBody value) {
            bodys.put(key, value);
            return this;
        }

        public Builder putBodys(Map<String, RequestBody> map) {
            bodys.putAll(map);
            return this;
        }

        public Builder addParams(String key, Object value) {
            params.put(key, value);
            return this;
        }

        public Builder putParams(Map<String, Object> map) {
            params.putAll(map);
            return this;
        }

        public Builder setObject(Boolean isObject) {
            this.isObject = isObject;
            return this;
        }

        public Builder setClass(Class<?> cls) {
            this.cls = cls;
            return this;
        }

        public CommandImpl create() {
            return new CommandImpl(url, params, fieldMap, bodys, isObject, cls);
        }

    }
}
